#include<stdio.h>
#include<stdbool.h>
#include<unistd.h>
#include<sys/types.h>
int main()
{
	//fork的演示
	//printf("i miss you\n");
	//fork();
	//printf("i love you\n");


	//fork返回值的探索
	printf("i am a process,pid:%d ,ppid:%d\n",getpid(), getppid());
	pid_t id =fork();
	if(id==0)
	{
		//子进程
		while(true)
		{
			printf("i am a child process, pid:%d, ppid:%d\n",getpid(),getppid());
			sleep(1);
		}
	}
	else if(id>0)
	{
		//父进程
		while(true)
		{
			printf(" i am a parent process, pid:%d, ppid:%d\n",getpid(),getppid());
			sleep(1);
		}
	}
	else
	{
		//error
	}

	//getppid和getpid的演示
	//pid_t pid = getpid();
	//pid_t ppid = getppid();
	//printf("I am a process, my pid is %d\n",pid);
	//printf("I am a process, my ppid is %d\n",ppid);
	return 0;
}
